package _1ChapterOne._6SplitTemporaryVariable;

public class Test1 {
    // 第一次的力
    double _primaryForce = 5.0;
    // 第二次的力
    double _secondaryForce = 8.0;
    // 物体重量
    int _mass = 5;
    // 延迟时间
    int _delay = 1;

    public double getDistinctTravelledOld(int time) {
        double result;
        double acc = _primaryForce / _mass;
        int primaryTime = Math.min(time, _delay);
        result = primaryTime * primaryTime * 0.5 * acc;
        int secondaryTime = time - _delay;
        if (secondaryTime > 0) {
            double primaryVal = acc * _delay;
            acc = (_primaryForce + _secondaryForce) / _mass;
            result += primaryVal * secondaryTime + primaryTime * primaryTime * 0.5 * acc;
        }
        return result;
    }

    public double getDistinctTravelledNew(int time) {
        double result;
        final double acc = _primaryForce / _mass;
        int primaryTime = Math.min(time, _delay);
        result = primaryTime * primaryTime * 0.5 * acc;
        int secondaryTime = time - _delay;
        if (secondaryTime > 0) {
            double primaryVal = acc * _delay;
            final double secondaryAcc = (_primaryForce + _secondaryForce) / _mass;
            result += primaryVal * secondaryTime + primaryTime * primaryTime * 0.5 * secondaryAcc;
        }
        return result;
    }
}
